/**
 * Framework for batch testing user profile models
 * Final project by Sergey Nepomnyachiy and Julia Polchin
 * Supervisor: Tsvi Kuflik
 *
 */
package core.generators.nested;

import interfaces.GeneratorInterface;

import java.util.Collection;
import java.util.Vector;

/**
 * Layer 2 generator - cuts out a part of the generated vector by the nested one 
 * @author Sergey and Julia
 * 
 */
public class SplitGenerator implements GeneratorInterface<Object> {
	/**
	 * Nested generator
	 */
	private GeneratorInterface<?> nested;
	private Vector<Object> vector = null;
	private int left;
	private int length;

	/**
	 * Constructor
	 * @param nested One nested generator
	 * @param left Where to start the cutting
	 * @param length How much to cuts?
	 */
	public SplitGenerator(GeneratorInterface<?> nested, int left, int length) {
		this.nested = nested;
		this.left = left;
		this.length = length;
		this.vector = null;

	}

	@Override
	public Object getScalar() {
		return null;
	}

	@Override
	public Collection<Object> getVector() {
		if (null == this.vector) {
			this.vector = new Vector<Object>();

			Object arr[] = this.nested.getVector().toArray();
			for (int col = this.left; col < this.left + this.length; ++col)
				this.vector.add(arr[col]);

		}
		return this.vector;
	}

	@Override
	public boolean is2D() {
		return true;
	}
}
